package com.heying.springcore.spel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class SpEl {

    @Value("#{666}") //注入内容666
    private int num;

    @Value("#{T(Math).PI}")
    private double pi;

    @Value("#{person}")//将名字为person的对象注入进来
    private Person person;

    @Value("#{person.name}")
    private String personName;

    @Value("#{person.helloworld()}")
    private String helloWorld;

    @Value("#{T(Math).random()}")
    private double random;

    @Value("#{'${list}'.split(',')}")
    private List<String> list;

    @Value("#{${map}}")
    private Map<String,String> map;

    @Value("#{person.computerList.^[band eq '红米']}")
    private Computer computer;

    @Value("#{person.computerList.?[band eq '绿米'].![price][0]}")
    private int price;

    @Override
    public String toString() {
        return "SpEl{" +
                "num=" + num +
                ", pi=" + pi +
                ", person=" + person +
                ", personName='" + personName + '\'' +
                ", helloWorld='" + helloWorld + '\'' +
                ", random=" + random +
                ", list=" + list +
                ", map=" + map +
                ", computer=" + computer +
                ", price=" + price +
                '}';
    }
}
